package velib.view;

import java.awt.event.ActionListener;
import velib.model.Borne;

public class DBConnectionFrame extends javax.swing.JFrame
{
    private velib.view.DBConnectionFrame dBConnectionFrame;
    private Borne[] bornes;

    /** Creates new form DBConnexionPanel */
    public DBConnectionFrame()
    {
        initComponents();
    }

    public DBConnectionFrame(Borne[] bornes)
    {
        this();
        this.bornes = bornes;
        setUpDBConnectionFrame();
    }

    public DBConnectionFrame getDBConnectionFrame()
    {
        return dBConnectionFrame;
    }

    public void addConnexionButtonListener(ActionListener al)
    {
        connexionButton.addActionListener(al);
    }

     //On rempli la combobox aves des objets bornes
    private void setUpDBConnectionFrame()   //On insere les bornes libres dans le menu éroulant
    {
        for (int i=0; i<bornes.length; i++)
        {
            listeBorneComboBox.addItem(bornes[i]);
        }
    }

    public Borne getBorneFromInput()    //On récupère la valeur sélectionnée dans le menu déroulant
    {
        Borne selectedBorne;
        selectedBorne = (Borne)listeBorneComboBox.getSelectedItem();
        return selectedBorne;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        listeBorneComboBox = new javax.swing.JComboBox();
        connexionButton = new javax.swing.JToggleButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(300, 200));

        connexionButton.setText("Connexion");

        jLabel1.setText("Authentification Interface");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(listeBorneComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(connexionButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(56, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(listeBorneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(connexionButton)
                .addContainerGap(28, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new UsersControlFrame().setVisible(true);
            }
        });
    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton connexionButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JComboBox listeBorneComboBox;
    // End of variables declaration//GEN-END:variables

}
